/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.uca.sisbec.actions.reportes;

import com.uca.sisbec.commons.HibernateAction;
import com.uca.sisbec.forms.reportes.ReporteCumPorCarreraForm;
import com.uca.sisbec.helpers.manto.CarreraHelper;
import com.uca.sisbec.helpers.manto.UniversidadHelper;
import com.uca.sisbec.helpers.reportes.ReporteCumPorCarreraHelper;
import com.uca.sisbec.mapping.Carrera;
import java.util.ArrayList;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

/**
 *
 * @author Juank
 */
public class ReporteCumPorCarreraAction extends HibernateAction {
    
    public ActionForward init(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response) throws Exception {
        
        UniversidadHelper uh = new UniversidadHelper(getSession(request));
        request.setAttribute("universidadList", uh.getAllUniversidades());
        
        request.setAttribute("carrerasList", new ArrayList<Carrera>());
        
        return mapping.findForward("success");
    }
    
    public ActionForward ConstruirReporteCumPorCarrera(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response) throws Exception {
        
        ReporteCumPorCarreraForm f = (ReporteCumPorCarreraForm) form;
        ReporteCumPorCarreraHelper helper = new ReporteCumPorCarreraHelper(getSession(request));
        request.setAttribute("reporte",helper.getReportList(f));
        
        
        return CargarCarreras(mapping,form,request,response);
    }
    
    public ActionForward CargarCarreras(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response) throws Exception {
        
        ReporteCumPorCarreraForm f = (ReporteCumPorCarreraForm) form;
        
        UniversidadHelper uh = new UniversidadHelper(getSession(request));
        request.setAttribute("universidadList", uh.getAllUniversidades());
        
        CarreraHelper ch = new CarreraHelper(getSession(request));
        request.setAttribute("carrerasList", ch.getAllCarreras(f.getUniversidad()));
        
        return mapping.findForward("success");
    }
}
